using System.Collections.Generic;
using System.ComponentModel;
using System.Web.Mvc;

namespace FluentMetadata.MvcIntegration
{
    public class FluentMetadataValidatorProvider : ModelValidatorProvider
    {
        public override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context)
        {
            var provider = new FluentMetadataProvider(TypeDescriptor.GetProvider(metadata.ModelType));

            var descriptor = provider.GetTypeDescriptor(metadata.ContainerType);

            yield return new FluentMetadataModelValidator(metadata, context, descriptor);
        }
    }
}